
#ifndef _RESOURCE_H_
#define _RESOURCE_H_

#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_image.h>
#include "misc.h"

namespace helper {


const size_t MAX_RESOURCE_NAME = 128;
class ResourceManager
{
private:
    template <class T> struct Node {
    public:
        char name[MAX_RESOURCE_NAME];
        T value;

        Node(const char *n)
        {
            strncpy(name, n, sizeof(name));
            //name[sizeof(name) - 1] = '\0';
        }
    };
    misc::SimpleList< Node<SDL_Surface *>* > image_list;
    misc::SimpleList< Node<Mix_Music *>* >   music_list;
    misc::SimpleList< Node<Mix_Chunk *>* >   chunk_list;
    misc::SimpleList< Node<char *>* >        text_list;

public:
    ResourceManager();
    virtual ~ResourceManager();
    void free_all();
    SDL_Surface *load_image(const char *path);
    Mix_Music *load_music(const char *path);
    Mix_Chunk *load_chunk(const char *path);
    void load_textcollection(const char *path);
    void load_all_in_dir(const char *dir);
    SDL_Surface *get_image(const char *name);
    Mix_Music *get_music(const char *name);
    Mix_Chunk *get_chunk(const char *name);
    const char *get_text(const char *name);
};





}//end namespace

#endif
